package Main;


import java.io.IOException;
import Gui.GameFrame;
import GameFiles.GameManager;
import EventManager.EventManager;

public class JFramePayDayMain
{

	public static void main(String[] args)
	{
		/**
		 * Initialization
		 */
		
		try
		{
			GameManager.getInstance().InitializeGame();
		} catch (IOException e1)
		{
			e1.printStackTrace();
		}
		JFrameGameWindow newGameFrame = new JFrameGameWindow();
		/**
		 * Game Loop
		 */
		long soon = 0;
		long now = System.currentTimeMillis();
		while (true)
		{
			now = System.currentTimeMillis();
			if (now >= soon)
			{
				// Throttle
				soon = now + 10;
				// Draw
				newGameFrame.repaint();
				
				//GameFrame.getInstance().revalidate();
				
				// TODO add actual time passed to UpdateProcesses
				EventManager.getInstance().processEvents();				
				// Update Game Logic
				GameManager.getInstance().getCurrentGameState().Execute();

			} else
			{
				try
				{
					Thread.sleep(1);
				} catch (Exception e)
				{
				}
			}
		}
		
	}

}
